package com.terrynoya.fight.data.parser.sff
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.utils.ByteArray;
	/**
	 * @author acer
	 */
	public class PNG8Maker
	{
		/**
		 * parse SFFSpriteNode data to bitmap
		 * @param rawData	1 byte is a index to palette
		 * @param width		bitmapWidth
		 * @param height	bitmapHeight
		 * @param palette	
		 * @return 
		 */
		public static function make(rawData:ByteArray,width:int,height:int,palette:Palette):Bitmap
		{
			var bmpData:BitmapData = new BitmapData(width, height,true,0);
			rawData.position = 0;
			for (var i : int = 0; i < height; i++) 
			{
				for (var j : int = 0; j < width; j++) 
				{
					var colorIndex:uint = rawData.readUnsignedByte();
					//第一个color为透明色
					var alpha:uint = colorIndex == 0 ? 0 : 0xff;
					var color:uint = palette.getColor(colorIndex,alpha);
					bmpData.setPixel32(j, i, color);
				}
			}
			return new Bitmap(bmpData);
		}
	}
}
